<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('教材列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>教材名称：</label>
                                <input type="text" name="bookName"/>
                            </li>
                            <li>
                                <label>难度级别：</label>
                                <select name="bookLevel" th:with="type=${@dict.getType('sys_level')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                                <input class="form-control" type="hidden" id="preidId" name="preidId" th:hidden="true" th:value="${preidId}">
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
    	var listFlag = [[${@permission.hasPermi('system:book:list')}]];
        var editFlag = [[${@permission.hasPermi('system:book:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:book:remove')}]];
        var bookLevelDatas = [[${@dict.getType('sys_level')}]];
        var statusDatas = [[${@dict.getType('sys_able_status')}]];
        var prefix = ctx + "system/book";

        $(function() {
            var options = {
                url: prefix + "/list2",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                sortName: "createTime",
		        sortOrder: "desc",
                modalName: "教材",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'bookId', 
                    title: '教材编号',
                    visible: false
                },
                {
                    title: '教材编号',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'bookName', 
                    title: '教材名称'
                },
                {
                    field: 'picture', 
                    title: '封面图片',
                    formatter: function(value, row, index) {
                    	return '<img src="'+value+'" width="25"/>';
                    }
                },
                {
                    field: 'bookLevel', 
                    title: '难度级别',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(bookLevelDatas, value);
                    }
                },
                {
                    field: 'songNum', 
                    title: '曲目数量'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + listFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.bookId + '\')"><i class="fa fa-list-ul"></i>添加单首曲目</a> ');
                         if('1'==row.addAllSongFlag){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" ><i class="fa fa-edit"></i>已添加所有曲目</a> ');
                        }else{
                           actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="addAllSong(\'' + row.bookId + '\')"><i class="fa fa-edit"></i>添加所有曲目</a> ');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        /*曲目列表-详细*/
		function detail(bookId) {
		    var preidId = $("#preidId").val();
		    var url = prefix + '/detail2/' + bookId+'/'+preidId;
		    $.modal.openTab("曲目数据", url);
		}

        /*添加该教材下的所有曲目*/
		function addAllSong(bookId) {
		    var preidId = $("#preidId").val();
            	var data =new FormData();
            	 data.append("preidId", preidId);
            	data.append("bookId",bookId);
                $.ajax({
                    url: prefix + "/add2",
                    data: data,
                    type: "post",
                    processData: false,
                    contentType: false,
                    success: function(result) {
                    	$.operate.ajaxSuccess(result);
                    }
                })
		}
    </script>
</body>
</html>